package fi.vamk.android;

import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.net.ParseException;
public class JSONParser {

	
//JSONObject
	public  static String getJSONFromUrl(String url) {
		String json = "";
	    HttpClient client = new DefaultHttpClient();
	    // Perform a GET request for a JSON list
	    HttpUriRequest request = new HttpGet(url);
	    // Get the response that sends back
	    HttpResponse response = null;
	    try {
	        response = client.execute(request);
	    } catch (ClientProtocolException e1) {
	        // TODO Auto-generated catch block
	        e1.printStackTrace();
	    } catch (IOException e1) {
	        // TODO Auto-generated catch block
	        e1.printStackTrace();
	    }

	    HttpEntity entity = response.getEntity();

	    try {
	        json = EntityUtils.toString(entity);
	       
	    } catch (ParseException e1) {
	        // TODO Auto-generated catch block
	        e1.printStackTrace();
	    } catch (IOException e1) {
	        // TODO Auto-generated catch block
	        e1.printStackTrace();
	    }
       
	    return json;
}
	    }